/**
 * This file is part of 1genia trampoline
 * Copyright (C) 2007 1genia (contact@1genia.com)
 *
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; version 3 of the License. 
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details. 
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; see the file COPYING.TXT.  If not,
 * write to the Free Software Foundation, Inc., 51 Franklin Street,
 * Fifth Floor, Boston, MA 02110-1301, USA. 
 **/
package com.genia.toolbox.form.editor.gui.view.internal.factory;

import com.genia.toolbox.basics.editor.gui.view.internal.AbstractViewFactory;
import com.genia.toolbox.basics.editor.gui.view.internal.panel.ElementViewPanel;
import com.genia.toolbox.form.editor.gui.FormEditorGUI;
import com.genia.toolbox.form.editor.gui.view.internal.FormDocumentInternalFrame;
import com.genia.toolbox.form.editor.gui.view.internal.panel.HorizontalFormViewPanel;
import com.genia.toolbox.form.editor.gui.view.internal.panel.ItemViewPanel;
import com.genia.toolbox.form.editor.gui.view.internal.panel.LabeledFormViewPanel;
import com.genia.toolbox.form.editor.gui.view.internal.panel.TabFormViewPanel;
import com.genia.toolbox.form.editor.gui.view.internal.panel.VerticalFormViewPanel;
import com.genia.toolbox.form.editor.model.document.impl.DocumentModel;
import com.genia.toolbox.form.editor.model.form.impl.FormModel;
import com.genia.toolbox.form.editor.model.form.impl.FormType;

/**
 * View factory, create the view according to the element.
 */
public class FormViewFactory
    extends AbstractViewFactory<FormEditorGUI, FormDocumentInternalFrame, DocumentModel, FormModel>
{

  /**
   * Constructor.
   * 
   * @param gui
   *          the gui.
   * @param internalFrame
   *          the internal frame.
   */
  public FormViewFactory(FormEditorGUI gui, FormDocumentInternalFrame internalFrame)
  {
    super(gui, internalFrame);
  }



  /**
   * Create a view.
   * 
   * @param model
   *          the element model.
   * @return the view.
   */
  @Override
  public ElementViewPanel<FormEditorGUI, FormDocumentInternalFrame, FormModel, FormType> createView(FormModel model)
  {
    ElementViewPanel<FormEditorGUI, FormDocumentInternalFrame, FormModel, FormType> panel = null;
    FormDocumentInternalFrame internalFrame = this.getInternalFrame();
    if (model.getType() == null) {
      return this.createSimpleView(model, internalFrame);
    }
    else if (FormType.HORIZONTAL.equals(model.getType())) {
      return this.createHorizontalView(model, internalFrame);
    }
    else if (FormType.VERTICAL.equals(model.getType())) {
      return this.createVerticalView(model, internalFrame);
    }
    else if (FormType.TAB.equals(model.getType())) {
      return this.createTabView(model, internalFrame);
    }
    else if (FormType.LABELED.equals(model.getType())) {
      return this.createLabeledView(model, internalFrame);
    }
    return panel;
  }



  /**
   * Create the simple view.
   * 
   * @param model
   *          the element model.
   * @param internalFrame
   *          the internal frame.
   * @return the linked view.
   */
  public ItemViewPanel createSimpleView(FormModel model, FormDocumentInternalFrame internalFrame)
  {
    ItemViewPanel panel = new ItemViewPanel(this.getGui(), internalFrame);
    panel.initialise();
    panel.setElement(model);
    return panel;
  }



  /**
   * Create the horizontal view.
   * 
   * @param model
   *          the element model.
   * @param internalFrame
   *          the internal frame.
   * @return the linked view.
   */
  public HorizontalFormViewPanel createHorizontalView(FormModel model, FormDocumentInternalFrame internalFrame)
  {
    HorizontalFormViewPanel panel = new HorizontalFormViewPanel(this.getGui(), internalFrame);
    panel.initialise();
    panel.setElement(model);
    return panel;
  }



  /**
   * Create the vertical view.
   * 
   * @param model
   *          the element model.
   * @param internalFrame
   *          the internal frame.
   * @return the linked view.
   */
  public VerticalFormViewPanel createVerticalView(FormModel model, FormDocumentInternalFrame internalFrame)
  {
    VerticalFormViewPanel panel = new VerticalFormViewPanel(this.getGui(), internalFrame);
    panel.initialise();
    panel.setElement(model);
    return panel;
  }



  /**
   * Create the labeled view.
   * 
   * @param model
   *          the element model.
   * @param internalFrame
   *          the internal frame.
   * @return the linked view.
   */
  public LabeledFormViewPanel createLabeledView(FormModel model, FormDocumentInternalFrame internalFrame)
  {
    LabeledFormViewPanel panel = new LabeledFormViewPanel(this.getGui(), internalFrame);
    panel.initialise();
    panel.setElement(model);
    return panel;
  }



  /**
   * Create the tab view.
   * 
   * @param model
   *          the element model.
   * @param internalFrame
   *          the internal frame.
   * @return the linked view.
   */
  public TabFormViewPanel createTabView(FormModel model, FormDocumentInternalFrame internalFrame)
  {
    TabFormViewPanel panel = new TabFormViewPanel(this.getGui(), internalFrame);
    panel.initialise();
    panel.setElement(model);
    return panel;
  }

}
